package com.jeebey.mybatis.dao;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.jeebey.mybatis.annotation.CascadeCache;
import com.jeebey.mybatis.bean.Group;
import com.jeebey.mybatis.generic.GenericDao;

@Repository
@CacheNamespace(implementation = org.mybatis.caches.ehcache.EhcacheCache.class, readWrite = true)
//@CacheNamespace(implementation = org.mybatis.caches.memcached.MemcachedCache.class, readWrite = true)
public interface GroupDao extends GenericDao<Group, Integer> {

	@Insert("INSERT INTO t_group (id,name) VALUES (#{id},#{name})")
	public void insertGroup(Group group);
	
	
	@Select("select * from t_group")
	@CascadeCache(clazz={UserDao.class})
	@Results(value = {
			@Result(property="id",column = "id"),
			@Result(property="name",column = "name"),
			@Result(property = "children", column = "{gid=id,name=name}", javaType = List.class, id = false, many = @Many(select = "net.lazytek.test.dao.UserDao.selectUsersByGroupId2")) })
	public List<Group> selectAllGroups();
	
}
